<?php
/**
 * @Copyright   2008, XXXX-XXXX
 * All rights reserved. 
 * feature summary.
 * @filesource:	context.php 
 * @author      	lipeng <lipengage@gmain.com> 
 * @version     	$Id: $ 
 * @package     	application
 * @subpackage    service
 */

/**
 * the class depend the context, get the request class name and the service class name
 */
class context {
	protected $service_classname = false;
	protected $request_classname = false;
	protected $uri = false;
	protected $locale = false;

	/**
	 * parse uri, get service_classname and request_classname
	 *
	 * @param $uri like $_SERVER['REQUEST_URI']
	 * @return no return
	 */
	public function __construct($uri) {
		if ($uri) {
			$this->uri = $uri;
			$pos = strpos($this->uri, '?');
			if (false == $pos) {
				$pos = strpos($this->uri, '&');
			}
			if (false == $pos) {
				$pos = strlen($this->uri);
			}
			$tmp_str = substr($this->uri, 0, $pos);
			$tmp_str = substr($tmp_str, (strrpos($tmp_str, '/')+1));
			$request_class = Config::app_get("request_class");
			$service_class = Config::app_get("service_class");
			$this->request_classname = empty($request_class[$tmp_str]) ? Config::get("class_service") : $request_class[$tmp_str];
			$this->service_classname = empty($service_class[$tmp_str]) ? Config::get("class_request") : $service_class[$tmp_str];
		}
		else {
			//TODO: because have not init service class, so must set class to service_classname
			//logger->notice();
		}
	}

	/**
	 *@param $request_classname one class name
	 */
	public function set_request_classname($request_classname) {
		if ($request_classname) {
			$this->request_classname = $request_classname;
		}
	}

	/**
	 *@param $service_classname one class name
	 */
	public function set_service_classname($service_classname) {
		if ($service_classname) {
			$this->service_classname = $service_classname;
		}
	}

	/**
	 *@param $uri like $_SERVER['REQUEST_URI']
	 */
	public function set_uri($uri) {
		if ($uri) {
			$this->uri = $uri;
		}
	}

	/**
	 *@return string like $_SERVER['REQUEST_URI']
	 */
	public function get_uri() {
		return $this->uri;
	}

	/**
	 *@return string one class name
	 */
	public function get_service_classname() {
		return $this->service_classname;
	}

	/**
	 *@return string one class name
	 */
	public function get_request_classname() {
		return $this->request_classname;
	}
}
?>